package org.hxzon.util;

import java.util.Calendar;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class DateIterator implements Iterator<Calendar> {
    private final Calendar endFinal;
    private final Calendar spot;
    private final int step;

    public DateIterator(Calendar startFinal, Calendar endFinal) {
        this(startFinal, endFinal, 1);
    }

    public DateIterator(Calendar startFinal, Calendar endFinal, int step) {
        super();
        this.step = step;
        this.endFinal = endFinal;
        spot = startFinal;
        spot.add(Calendar.DATE, -step);
    }

    public boolean hasNext() {
        return spot.before(endFinal);
    }

    public Calendar next() {
        spot.add(Calendar.DATE, step);
        if (spot.after(endFinal)) {
            throw new NoSuchElementException();
        }
        return (Calendar) spot.clone();
    }

    public void remove() {
        throw new UnsupportedOperationException();
    }
}
